package cn.zhage.aimin.drug1.controller;

/*
 *
 * @author 渣哥
 */

import cn.zhage.aimin.base.response.Result;
import cn.zhage.aimin.drug1.entity.Drug;
import cn.zhage.aimin.drug1.service.DrugService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drug")
@RequiredArgsConstructor
public class DrugController {

    private final DrugService drugService;

    @RequestMapping("/getAll")
    public Result<?> getAll1() {
        List<Drug> list = drugService.list();
        return Result.success(list);
    }

    @RequestMapping("/list")
    public Result<?> getAll() {
        List<Drug> list = drugService.list();
        return Result.success(list);
    }

    // get http://localhost:8083/aimin-drug/drug/getById1?aid=1   url
    @RequestMapping("/getById1")
    public Result<?> getById1(@RequestParam("aid") String b) {
        Drug byId = drugService.getById(b);
        return Result.success(byId);
    }

    // get http://localhost:8083/aimin-drug/drug/1   全球资源定位符
    // get 获取
    // post 新增
    // put 修改
    // delete 删除  head
    @RequestMapping("/{id}")
    public Result<?> getById(@PathVariable Integer id) {
        Drug byId = drugService.getById(id);
        return Result.success(byId);
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        drugService.removeById(id);
        return Result.success();
    }

    @GetMapping("/categoryId/{categoryId}")
    public Result<?> findDrugByCategoryId(@PathVariable Integer categoryId) {
        List<Drug> list = drugService.findDrugByCategoryId(categoryId);
        return Result.success(list);
    }

    @GetMapping("/list")
    public Result<?> list() {
        List<Drug> list = drugService.list();
        return Result.success(list);
    }








}
